﻿@{
    ViewBag.Title = "Page1";
    Layout = "~/Views/Shared/Master_EasyUI.cshtml";
}
<style>
    tr {
        padding: 5px;
    }
</style>
<div class="easyui-layout" data-options="fit:true" style="margin: 1px; padding: 1px;">
    <div id="datacenter" data-options="region:'center',border:false" style="text-align: center; vertical-align: middle;">
        <form id="fm" method="post" novalidate style="visibility: hidden; margin: 0 auto;">
            <table style="margin: 0 auto; vertical-align: middle;">
                <tr>
                    <td class="tdleft">渠道：</td>
                    <td class="tdright" colspan="3">
                        <input id="TXT_QD" name="TXT_QD" class=" easyui-textbox" missingmessage="请输入渠道" style="width: 300px; height: 25px;" />
                    </td>
                </tr>
                <tr>
                    <td class="tdleft">活动编码：</td>
                    <td class="tdright" colspan="3">
                        <input type="text" id="TXT_BM" name="TXT_BM" class="easyui-textbox" missingmessage="请输入活动编码" style="width: 300px;height: 25px;" />
                    </td>
                </tr>
                <tr>
                    <td class="tdleft">活动名称：</td>
                    <td class="tdright" colspan="3">
                        <input type="text" id="TXT_NAME" name="TXT_NAME" class=" easyui-textbox" missingmessage="请输入活动名称" style="width: 300px;height: 25px;" />
                    </td>
                </tr>
                <tr>
                    <td class="tdleft">描述：</td>
                    <td class="tdright" colspan="3">
                        <input type="text" id="TXT_MS" name="TXT_MS" class=" easyui-textbox" missingmessage="请输入描述" style="width: 300px;height: 25px;" />
                    </td>
                </tr>
                <tr>
                    <td class="tdleft">选择车系：</td>
                    <td class="tdright">
                        是否显示：<input type="radio" name="issee" value="1" />是<input type="radio" name="issee" value="0" />否&nbsp;|&nbsp;是否必填：<input type="radio" name="allowblank" value="1" />是<input type="radio" name="allowblank" value="0" />否&nbsp;|&nbsp;是否只读：<input type="radio" name="readonly" value="1" />是<input type="radio" name="readonly" value="0" />否&nbsp;
                        |&nbsp;<br />
                        <br />
                        默认值：<input type="text" class="easyui-combobox" id="TXT_BRAND" style="width: 130px; height: 25px;" placeholder="选择品牌" />
                        &nbsp;<input type="text" class="easyui-combobox" id="TXT_SERIES" style="width: 130px;height: 25px;" />
                    </td>
                </tr>
                <tr>
                    <td class="tdleft">选择离您最近的4S店：</td>
                    <td class="tdright">
                        是否显示：<input type="radio" name="issee1" value="1" />是<input type="radio" name="issee1" value="0" />否&nbsp;|&nbsp;是否必填：<input type="radio" name="allowblank1" value="1" />是<input type="radio" name="allowblank1" value="0" />否&nbsp;|&nbsp;是否只读：<input type="radio" name="readonly1" value="1" />是<input type="radio" name="readonly1" value="0" />否&nbsp;
                        |&nbsp;<br />
                        <br/>默认值：<input type="text" class="easyui-combobox" id="TXT_PROVINCE" style="width: 100px; height: 25px;"/>&nbsp;
                        <input type="text" class="easyui-combobox" id="TXT_CITY" style="width: 100px;height: 25px;" />&nbsp;
                        <input type="text" class="easyui-combobox" id="TXT_TOWN" style="width: 100px; height: 25px;" />&nbsp;
                        <input type="text" class="easyui-combobox" id="TXT_JXS" style="width: 100px;height: 25px;" />
                    </td>
                </tr>
                <tr id="tr1">
                    <td class="tdleft">计划到店时间：</td>
                    <td class="tdright">
                        是否显示：<input type="radio" name="issee2" value="1" />是<input type="radio" name="issee2" value="0" />否&nbsp;|&nbsp;是否必填：<input type="radio" name="allowblank2" value="1" />是<input type="radio" name="allowblank2" value="0" />否&nbsp;|&nbsp;是否只读：<input type="radio" name="readonly2" value="1" />是<input type="radio" name="readonly2" value="0" />否&nbsp;
                        |&nbsp;<br />
                        <br />默认值：<input type="text" class="easyui-datebox" id="TXT_DDDATE" style="width: 130px;height: 25px;" />&nbsp;<a href="javascript:void(0)" id="btnreset" class="easyui-linkbutton c6" data-options="iconCls:''" style="width: 90px">重 置</a>
                    </td>
                </tr>
                <tr id="tr2">
                    <td class="tdleft">计划购车时间：</td>
                    <td class="tdright">
                        是否显示：<input type="radio" name="issee3" value="1" />是<input type="radio" name="issee3" value="0" />否&nbsp;|&nbsp;是否必填：<input type="radio" name="allowblank3" value="1" />是<input type="radio" name="allowblank3" value="0" />否&nbsp;|&nbsp;是否只读：<input type="radio" name="readonly3" value="1" />是<input type="radio" name="readonly3" value="0" />否&nbsp;
                        |&nbsp;<br />
                        <br />默认值：<input type="text" class="easyui-datebox" id="TXT_BUYDATE" style="width: 130px;height: 25px;" />&nbsp;<a href="javascript:void(0)" id="btnreset1" class="easyui-linkbutton c6" data-options="iconCls:''" style="width: 90px">重 置</a>
                    </td>
                </tr>
            </table>
        </form>
        <div id="dlg-buttons" style="visibility: hidden; margin-top: 10px;">
            <a href="javascript:void(0)" id="btnsave" class="easyui-linkbutton c6" data-options="iconCls:'icon-ok'" style="width: 90px">保 存</a>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('#fm,#dlg-buttons').css('visibility', 'visible');
        //是否显示radio默认值
        $("input[name='issee'][value=1]").attr("checked", true);
        $("input[name='issee1'][value=1]").attr("checked", true);
        $("input[name='issee2'][value=1]").attr("checked", true);
        $("input[name='issee3'][value=1]").attr("checked", true);
        //是否必填radio默认值
        $("input[name='allowblank'][value=1]").attr("checked", true);
        $("input[name='allowblank1'][value=1]").attr("checked", true);
        $("input[name='allowblank2'][value=1]").attr("checked", true);
        $("input[name='allowblank3'][value=1]").attr("checked", true);
        //是否只读radio默认值
        $("input[name='readonly'][value=0]").attr("checked", true);
        $("input[name='readonly1'][value=0]").attr("checked", true);
        $("input[name='readonly2'][value=0]").attr("checked", true);
        $("input[name='readonly3'][value=0]").attr("checked", true);
        //重置
        $("#btnreset").click(function () { $("#tr1").find("input").val(""); });
        $("#btnreset1").click(function () { $("#tr2").find("input").val(""); });

        $('#TXT_BRAND').combobox({
            url: '/Home/GetBrand',
            valueField: 'id',
            textField: 'text',
            onSelect: function (record) {

                $('#TXT_SERIES').combobox('clear');
                $('#TXT_SERIES').combobox({
                    url: '/Home/GetSeriesByBrand?id=' + record.id,
                    valueField: 'id',
                    textField: 'text'
                }).combobox('selectedIndex', 0);
            }
        });//.combobox('selectedIndex', 0);
        $('#TXT_BRAND').combobox('setValue', '-----品牌-----');

        $('#TXT_SERIES').combobox({
            url: '/Home/GetSeriesByBrand?id=2010010100000001', //+ record.id,
            valueField: 'id',
            textField: 'text'
        });//.combobox('selectedIndex', 0);
        $('#TXT_SERIES').combobox('setValue', '-----车系-----');

        $('#TXT_PROVINCE').combobox({
            url: '/Home/GetProvince',
            valueField: 'id',
            textField: 'text',
            onSelect: function (record) {

                $('#TXT_CITY').combobox('clear');
                $('#TXT_CITY').combobox({
                    url: '/Home/GetCityByProvince?id=' + record.id,
                    valueField: 'id',
                    textField: 'text',
                    onSelect: function (record) {

                        $('#TXT_TOWN').combobox('clear');
                        $('#TXT_TOWN').combobox({
                            url: '/Home/GetTownByCity?id=' + record.id,
                            valueField: 'id',
                            textField: 'text'
                        }); //.combobox('selectedIndex', 0);
                        $('#TXT_TOWN').combobox('setValue', '-----地区-----');
                    },
                    onChange: function (newValue, oldValue) {
                        $('#TXT_TOWN').combobox('clear');
                        $('#TXT_TOWN').combobox({
                            url: '/Home/GetTownByCity?id=' + newValue,
                            valueField: 'id',
                            textField: 'text'
                        }); //.combobox('selectedIndex', 0);
                        $('#TXT_TOWN').combobox('setValue', '-----地区-----');
                    }
                }); //.combobox('selectedIndex', 0);
                $('#TXT_CITY').combobox('setValue', '-----城市-----');
            }
        });
        $('#TXT_PROVINCE').combobox('setValue', '-----省份-----');
        $('#TXT_CITY').combobox('setValue', '-----城市-----');
        $('#TXT_TOWN').combobox('setValue', '-----地区-----');
        $('#TXT_JXS').combobox('setValue', '-----经销商-----');


        //提交
        $("#btnsave").click(function () {
            //fm

            var obj = new Object();
            obj.TXT_QD = $('#TXT_QD').val();
            obj.TXT_BM = $('#TXT_BM').val();
            obj.TXT_NAME = $('#TXT_NAME').val();
            obj.TXT_MS = $('#TXT_MS').val();

            obj.CARISSEE = $("input[name=issee]:checked").val();
            obj._4SISSEE = $("input[name=issee1]:checked").val();
            obj.SJISSEE = $("input[name=issee2]:checked").val();
            obj.GCISSEE = $("input[name=issee3]:checked").val();

            obj.CARMUST = $("input[name=allowblank]:checked").val();
            obj._4SMUST = $("input[name=allowblank1]:checked").val();
            obj.SJMUST = $("input[name=allowblank2]:checked").val();
            obj.GCMUST = $("input[name=allowblank3]:checked").val();

            obj.CARREAD = $("input[name=readonly]:checked").val();
            obj._4SRREAD = $("input[name=readonly1]:checked").val();
            obj.SJRREAD = $("input[name=readonly2]:checked").val();
            obj.GCRREAD = $("input[name=readonly3]:checked").val();

            obj.TXT_DDDATE = $('#TXT_DDDATE').datetimebox('getValue');//$('#TXT_DDDATE').val();
            obj.TXT_BUYDATE = $('#TXT_BUYDATE').datetimebox('getValue');//.val();

            obj.TXT_BRAND = $('#TXT_BRAND').combobox('getValue');//.val();
            obj.TXT_SERIES = $('#TXT_SERIES').combobox('getValue');//.val();

            obj.TXT_PROVINCE = $('#TXT_PROVINCE').combobox('getValue');//.val();
            obj.TXT_CITY = $('#TXT_CITY').combobox('getValue');//.val();
            obj.TXT_TOWN = $('#TXT_TOWN').combobox('getValue');//.val();
            obj.TXT_JXS = $('#TXT_JXS').combobox('getValue');//.val();



            $.ajax({
                type: "POST",
                contentType: "application/json;utf-8",
                url: "/Home/SaveSetting",
                data: "{json:'" + $.toJSON(obj) + "'}",
                dataType: "",
                success: function (data, textStatus) {
                    alert(data);
                },
                complete: function (XMLHttpRequest, textStatus) {
                    //HideLoading();
                },
                error: function (statusText, responseText) {
                    //请求出错处理
                    alert(statusText.responseText);
                }
            });

        });

    });


    $.extend($.fn.combobox.methods, {
        selectedIndex: function (jq, index) {
            if (!index) {
                index = 0;
            }
            $(jq).combobox({
                onLoadSuccess: function () {
                    var opt = $(jq).combobox('options');
                    var data = $(jq).combobox('getData');

                    for (var i = 0; i < data.length; i++) {
                        if (i == index) {
                            $(jq).combobox('setValue', eval('data[index].' + opt.valueField));
                            break;
                        }
                    }
                }
            });
        }
    });
</script>
